//
//  StepTableViewCell.m
//  ThePrivateKitchen
//
//  Created by lirui on 16/1/26.
//  Copyright © 2016年 www.lanou3g.com蓝鸥科技. All rights reserved.
//

#import "StepTableViewCell.h"

@interface StepTableViewCell ()
@property (nonatomic, retain) UIImageView *stepImageView;
@property (nonatomic, retain) UILabel *stepLabel;

@end
@implementation StepTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        /*
         *  stepImageView
         */
        // 初始化
        self.stepImageView = [[UIImageView alloc] init];
        
        // 将dishImageView加入cell.contentView
        [self.contentView addSubview:self.stepImageView];
        
        // 内存管理
        [self.stepImageView release];
        
        /*
         *  stepLabel
         */
        // 初始化
        self.stepLabel = [[UILabel alloc] init];
        
        // 不限行数
        self.stepLabel.numberOfLines = 0;
        
        // 将dishLabel加入cell.contentView
        [self.contentView addSubview:self.stepLabel];
        
        // 内存管理
        [self.stepLabel release];
    }
    return self;
}
- (void)layoutSubviews
{
    // 调用父类布局方法
    [super layoutSubviews];
    // 设置stepImageView的frame
    self.stepImageView.frame = CGRectMake(10 * WIDTH, 10 *HEIGHT, WIDTH *375 - 20  ,HEIGHT *150 );
    
    // 设置stepLabel的frame
    self.stepLabel.frame = CGRectMake(10 * WIDTH ,HEIGHT *160, WIDTH *375 -20  ,HEIGHT * 50);
}
- (void)setStepDic:(NSDictionary *)stepDic
{
    // retain类型赋值
    if (_stepDic != stepDic) {
        [_stepDic release];
        _stepDic = [stepDic retain];
    }
    // stepImageView赋值
    [self.stepImageView sd_setImageWithURL:stepDic[@"dishes_step_image"]];
    // placeholderImage:[UIImage imageNamed:@"jiazaitu"]];
    
    // stepLabel赋值
    self.stepLabel.text = [NSString stringWithFormat:@"%ld %@", self.num, stepDic[@"dishes_step_desc"]];
    
  }

+ (CGFloat)heightWithText:(NSString *)text
                     font:(UIFont *)font
                     size:(CGSize)size
{
    // 设置一个字典 保存文本属性
    NSDictionary *dic = @{NSFontAttributeName : font};
    // 预设尺寸 文本最大不会超过这个尺寸
    //    CGSize size = CGSizeMake(375 - 20, 1000);
    // 根据文本信息 计算得到一个CGRect
    // 参数1: 尺寸范围
    // 参数2: 获取文本尺寸的方式
    // 参数3: 文本属性
    // 参数4: 无用信息(上下文)
    CGRect rect = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    // 返回得到的高度
    return rect.size.height;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
